Inside Macintosh: Sound

| Previous | Chapter contents | Chapter top | Section top | Next |

Sound Resources

A sound resource is a resource of type 'snd ' that contains sound commands and possibly also sound data. Sound resources are widely used by Macintosh applications that produce sounds. These resources provide a simple and portable way for you to incorporate sounds into your application. For example, the sounds that a user can select in the Sound control panel as the system alert sound are stored in the System file as 'snd ' resources.

There are two types of 'snd ' resources, known as format 1 and format 2. Figure 1-20 illustrates the structures of both kinds of 'snd ' resources.

Figure 20 The structure of 'snd ' resources

The format 2 'snd ' resource is obsolete. Your application should create only format 1 'snd ' resources. The format 2 'snd ' resource was designed for use by HyperCard and can be used with sampled-sound data only.

Resource IDs for 'snd ' resources in the range 0 to 8191 are reserved for use by Apple Computer, Inc. The 'snd ' resources numbered 1 through 4 are defined to be the standard system alert sounds, although more recent versions of system software have included more standard system alert sounds.

When a sound command contained in an 'snd ' resource has associated sound data, the high bit of the command is set. This changes the meaning of the param2 field of the command from a pointer to a location in RAM to an offset value that specifies the offset in bytes from the resource's beginning to the location of the associated sound data (such as a sampled sound header). Figure 1-21 illustrates the location of this data offset bit.

Figure 21 The location of the data offset bit

The offset bit is used only by sound commands that are stored in sound resources of type  'snd ' and that have associated sound data (that is, sampled-sound or wave-table data).

You can use a constant to access that flag.

CONST
    dataOffsetFlag          = $8000;     {sound command data offset bit}

If the dataOffsetFlag bit is not set, param2 is interpreted instead as a pointer to the location in memory (outside the sound resource) where the data is located.

The first few bytes of the resource contain 'snd ' header information and are a different size for each format. An audio data type specified in a format 1 'snd ' requires 6 bytes. The number of data types multiplied by 6 is added to this offset. The number of commands multiplied by 8 bytes, the size of a sound command, is added to the offset.

The Format 1 Sound Resource

The Format 2 Sound Resource


© 1998 Apple Computer, Inc.

| Previous | Chapter contents | Chapter top | Section top | Next |